package recursion;

/**
 * Class to generate all the permutations ( or anagrams) of a string.
 * http://stackoverflow.com/questions/4240080/generating-all-permutations-of-a-given-string
 * 
 * Timing complexity: O(n!)
 * 
 * */
public class Permutations {

	public static void permute(String prefix, String str){
		if(str.length() == 0){
			System.out.println(prefix);
		}
		
		int len = str.length();
		for(int i = 0; i < len; i++){
			permute(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1));
		}
	}
	
	public static void main(String[] args){
		permute("", "abcd");
	}
	
}
